﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using PPI.General;

namespace PPI.Entities.Settings
{
    public class ESettingsBase : ICloneable
    {
        protected string m_SettingKey;
        private string m_SettingValue;
        private Int32 m_SettingId;
        private string m_SettingText;


        public string SettingValue
        {
            get { return m_SettingValue; }
            set { m_SettingValue = value; }
        }
        public Int32 SettingId
        {
            get { return m_SettingId; }
            set { m_SettingId = value; }
        }
        public string SettingKey
        {
            get { return m_SettingKey; }
        }
        public string SettingText
        {
            get { return m_SettingText; }
            set { m_SettingText = value; }
        }

        public ESettingsBase()
        {
            m_SettingId = Int32.MinValue;
            m_SettingValue = string.Empty;
        }

        public ESettingsBase(Int32 id, string value )
        :this()
        {
            m_SettingId = id;
            m_SettingValue = value;
        }

        public ESettingsBase(Int32 id, string value, string text)
            : this(id,value)
        {
            m_SettingText = text;
        }

        public XmlNode CreateNode(XmlDocument document)
        {
            XmlNode _SettingNode = document.CreateElement("Setting");
            XmlAttribute _IdAttribute = document.CreateAttribute("Key");
            _IdAttribute.Value = m_SettingKey;
            _SettingNode.Attributes.Append(_IdAttribute);

            XmlNode _SettingIdNode = document.CreateElement("Id");
            _SettingIdNode.AppendChild(document.CreateTextNode(m_SettingId.ToString()));
            _SettingNode.AppendChild(_SettingIdNode);

            XmlNode _SettingTextNode = document.CreateElement("Text");
            _SettingTextNode.AppendChild(document.CreateTextNode(m_SettingText));
            _SettingNode.AppendChild(_SettingTextNode);


            XmlNode _SettingValueNode = document.CreateElement("Value");
            _SettingValueNode.AppendChild(document.CreateTextNode(m_SettingValue));
            _SettingNode.AppendChild(_SettingValueNode);
            return _SettingNode;
        }

        public object Clone()
        {
            ESettingsBase returnObject = new ESettingsBase();
            returnObject.m_SettingKey = m_SettingKey;
            return returnObject;
        }
    }
}
